package com.itheima.wms.controller;

import com.itheima.wms.pojo.PageFactory;
import com.itheima.wms.pojo.Warehouse;
import com.itheima.wms.service.FactoryService;
import com.itheima.wms.utils.PageBean;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping(path = "/warehouse")
public class FactoryController {
    private final FactoryService factoryService;

    /**
     * 新增仓库
     */
    @PostMapping
    public Result<String> addFactory(@RequestBody Warehouse warehouse) {
        factoryService.addFactory(warehouse);
        return Result.success("新增成功");
    }

    /**
     * 分页查询
     */
    @GetMapping(path = "/page")
    public Result<PageBean<Warehouse>> queryFactoryAll(PageFactory queryPage) {
        PageBean<Warehouse> warehousePageBean = factoryService.queryFactoryAll(queryPage);
        return Result.success(warehousePageBean);
    }

    /**
     * 编辑回显
     */
    @GetMapping(path = "/{id}")
    public Result<Warehouse> queryFactoryById(@PathVariable("id") Integer id) {
        Warehouse factory=factoryService.queryFactoryById(id);
        return Result.success(factory);
    }

    /**
     * 修改数据
     */
    @PutMapping
    public Result<String> updateFactory(@RequestBody Warehouse warehouse) {
        factoryService.updateFactory(warehouse);
        return Result.success("修改成功");
    }

    /**
     * 删除仓库
     */
    @DeleteMapping
    public Result<String> deleteFactoryByIds(@RequestParam("ids") Integer[] ids) {
        factoryService.deleteFactoryByIds(ids);
        return Result.success("删除成功");
    }

    /**
     * 查询仓库
     */
    @GetMapping(path = "/list")
    public Result<List<Warehouse>> queryFactoryList(Integer status) {
        List<Warehouse> factoryList= factoryService.queryFactoryList(status);
        return Result.success(factoryList);
    }
}
